<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Insert Data into Database</title>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&family=Roboto:wght@400;500&display=swap" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Poppins', sans-serif;
        }

        body {
            background-color: #f5f7fa;
            color: #333;
            display: flex;
            flex-direction: column;
            align-items: center;
            height: 100vh;
        }

        .navbar {
            width: 100%;
            background-color: #fff;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            padding: 10px 20px;
            position: fixed;
            top: 0;
            z-index: 1000;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .navbar a.logo {
            font-size: 24px;
            color: #4CAF50;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 1px;
            text-decoration: none;
        }

        .navbar a {
            color: #333;
            text-decoration: none;
            margin-left: 20px;
            font-size: 16px;
            position: relative;
        }

        .navbar a::after {
            content: '';
            display: block;
            width: 0;
            height: 2px;
            background: #4CAF50;
            transition: width .3s;
            position: absolute;
            bottom: -5px;
            left: 0;
        }

        .navbar a:hover::after {
            width: 100%;
        }

        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 600px;
            margin-top: 100px; /* Adjusted for the fixed navbar */
        }

        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 20px;
            font-family: 'Roboto', sans-serif;
        }

        label {
            font-weight: bold;
            color: #555;
            display: block;
            margin-bottom: 5px;
        }

        input[type="text"], textarea {
            width: 100%;
            padding: 10px;
            margin-bottom: 20px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
            font-family: 'Roboto', sans-serif;
        }

        textarea {
            resize: vertical;
            height: 100px;
        }

        button {
            display: block;
            width: 100%;
            padding: 10px;
            background-color: #4CAF50;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            font-family: 'Roboto', sans-serif;
        }

        button:hover {
            background-color: #388E3C;
        }

        #response {
            margin-top: 20px;
            font-size: 16px;
            color: #4CAF50;
            text-align: center;
        }

        @media (max-width: 768px) {
            .navbar a {
                display: block;
                margin: 10px 0;
            }
        }
    </style>
</head>
<body>
    <div class="navbar">
        <a href="#" class="logo">OJ Platform ☰</a>
        <a href="/bch" class="home">首页</a>
    </div>
    <div class="container">
        <h1>添加题目</h1>
        <form id="dataForm">
            <label for="title">标题:</label>
            <textarea id="title" name="title"></textarea>

            <label for="star">难度:</label>
            <input type="text" id="star" name="star">

            <label for="desc">描述:</label>
            <textarea id="desc" name="desc"></textarea>

            <label for="header">预设代码:</label>
            <textarea id="header" name="header"></textarea>

            <label for="tail">测试用例:</label>
            <textarea id="tail" name="tail"></textarea>

            <button type="button" onclick="insertData()">Submit</button>
        </form>
        <p id="response"></p>
    </div>
    <script>
        function insertData() {
            const title = document.getElementById('title').value;
            const star = document.getElementById('star').value;
            const desc = document.getElementById('desc').value;
            const header = document.getElementById('header').value;
            const tail = document.getElementById('tail').value;

            const data = {
                title: title,
                star: star,
                desc: desc,
                header: header,
                tail: tail
            };

            fetch('/submit', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(data)
            })
            .then(response => response.text())
            .then(data => {
                document.getElementById('response').innerText = data;
            })
            .catch(error => {
                console.error('Error:', error);
                document.getElementById('response').innerText = 'Error: ' + error;
            });
        }
    </script>
</body>
</html>